package com.api.weavernorth.statement;

import com.alibaba.fastjson.JSONObject;
import com.weavernorth.promotionPlan.service.promPlanService;
import com.weavernorth.statement.service.mallStateMentService;
import com.weavernorth.util.Logger4jUtil;
import org.apache.log4j.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @Author: bruseewang
 * @Package: com.api.weavernorth.statement
 * @date: 2021/6/18 11:18
 * @description: sap接口传数至oa，自动创建商场对账单流程
 * 接口地址：http://testoa.chinaerdos.com:8081/api/Mall/statement
 */
@Path("/Mall")
public class statementApi extends HttpServlet {
//    private Logger log = Logger4jUtil.getLoggerByName("/action/api/statementApi/");
    @POST
    @Path("/statement")
    @Produces(MediaType.APPLICATION_JSON)
    public String promotionPlanApi(@Context HttpServletRequest httpservletrequest, @Context HttpServletResponse httpservletresponse, JSONObject jsonObject){
        Logger log =Logger4jUtil.getLoggerByName("/action/api/statementApi/");
        String localDate=new SimpleDateFormat("yyyyMMdd").format(Calendar.getInstance().getTime());
        log.info("商场对账单自动创建流程接口：");
        JSONObject jsonReturn =null;
        if(!jsonObject.isEmpty()){
            log.info("SAP传过来的数据："+jsonObject.toString());
            log.info("当前日期："+localDate);
            mallStateMentService service = new mallStateMentService();

            try {
                jsonReturn=service.createWorkFlow(log,jsonObject);
            }catch (Exception ex){
                jsonReturn=new JSONObject();
                jsonReturn.put("status","F");
                jsonReturn.put("message","接口调用失败,异常信息："+jsonReturn.toString());

            }
        }else{
            jsonReturn.put("status","F");
            jsonReturn.put("message","接口调用失败,请填装数据！");
        }

        return jsonReturn.toString();
    }
}
